package cn.edu.sdjzu.xg.eagle.bysj.controller;

import cn.edu.sdjzu.xg.eagle.bysj.annotation.IgnoreAuth;
import cn.edu.sdjzu.xg.eagle.bysj.annotation.SysLog;
import cn.edu.sdjzu.xg.eagle.bysj.entity.BaoxiaozhiduEntity;
import cn.edu.sdjzu.xg.eagle.bysj.entity.view.BaoxiaozhiduView;
import cn.edu.sdjzu.xg.eagle.bysj.service.Interface.BaoxiaozhiduService;
import cn.edu.sdjzu.xg.eagle.bysj.utils.MPUtil;
import cn.edu.sdjzu.xg.eagle.bysj.utils.PageUtils;
import cn.edu.sdjzu.xg.eagle.bysj.utils.R;
import com.baomidou.mybatisplus.mapper.EntityWrapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.Map;

/**
 * 报销制度
 * 后端接口
 * @author 
 * @email 
 * @date 2025-06-02 13:29:27
 */
@RestController
@RequestMapping("/baoxiaozhidu")
public class BaoxiaozhiduController {
    @Autowired
    private BaoxiaozhiduService baoxiaozhiduService;









    /**
     * 后台列表
     */
    @RequestMapping("/page")
    public R page(@RequestParam Map<String, Object> params, BaoxiaozhiduEntity baoxiaozhidu,
                  HttpServletRequest request){
                                    EntityWrapper<BaoxiaozhiduEntity> ew = new EntityWrapper<BaoxiaozhiduEntity>();
                                                                                                                    
        
        
        PageUtils page = baoxiaozhiduService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, baoxiaozhidu), params), params));
        return R.ok().put("data", page);
    }







    /**
     * 前端列表
     */
	@IgnoreAuth
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params,BaoxiaozhiduEntity baoxiaozhidu,
		HttpServletRequest request){
        EntityWrapper<BaoxiaozhiduEntity> ew = new EntityWrapper<BaoxiaozhiduEntity>();

		PageUtils page = baoxiaozhiduService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, baoxiaozhidu), params), params));
        return R.ok().put("data", page);
    }

	/**
     * 列表
     */
    @RequestMapping("/lists")
    public R list( BaoxiaozhiduEntity baoxiaozhidu){
       	EntityWrapper<BaoxiaozhiduEntity> ew = new EntityWrapper<BaoxiaozhiduEntity>();
      	ew.allEq(MPUtil.allEQMapPre( baoxiaozhidu, MPUtil.camelToSnake("baoxiaozhidu")));
        return R.ok().put("data", baoxiaozhiduService.selectListView(ew));
    }

	 /**
     * 查询
     */
    @RequestMapping("/query")
    public R query(BaoxiaozhiduEntity baoxiaozhidu){
        EntityWrapper< BaoxiaozhiduEntity> ew = new EntityWrapper< BaoxiaozhiduEntity>();
 		ew.allEq(MPUtil.allEQMapPre( baoxiaozhidu, MPUtil.camelToSnake("baoxiaozhidu")));
		BaoxiaozhiduView baoxiaozhiduView =  baoxiaozhiduService.selectView(ew);
		return R.ok("查询报销制度成功").put("data", baoxiaozhiduView);
    }
	
    /**
     * 后端详情
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
        BaoxiaozhiduEntity baoxiaozhidu = baoxiaozhiduService.selectById(id);
		baoxiaozhidu = baoxiaozhiduService.selectView(new EntityWrapper<BaoxiaozhiduEntity>().eq("id", id));
        return R.ok().put("data", baoxiaozhidu);
    }

    /**
     * 前端详情
     */
	@IgnoreAuth
    @RequestMapping("/detail/{id}")
    public R detail(@PathVariable("id") Long id){
        BaoxiaozhiduEntity baoxiaozhidu = baoxiaozhiduService.selectById(id);
		baoxiaozhidu = baoxiaozhiduService.selectView(new EntityWrapper<BaoxiaozhiduEntity>().eq("id", id));
        return R.ok().put("data", baoxiaozhidu);
    }
    



    /**
     * 后端保存
     */
    @RequestMapping("/save")
    @SysLog("新增报销制度")
    public R save(@RequestBody BaoxiaozhiduEntity baoxiaozhidu, HttpServletRequest request){
    	//ValidatorUtils.validateEntity(baoxiaozhidu);
        baoxiaozhiduService.insert(baoxiaozhidu);
        return R.ok();
    }
    
    /**
     * 前端保存
     */
    @SysLog("新增报销制度")
    @RequestMapping("/add")
    public R add(@RequestBody BaoxiaozhiduEntity baoxiaozhidu, HttpServletRequest request){
    	//ValidatorUtils.validateEntity(baoxiaozhidu);
        baoxiaozhiduService.insert(baoxiaozhidu);
        return R.ok();
    }



    /**
     * 修改
     */
    @RequestMapping("/update")
    @Transactional
    @SysLog("修改报销制度")
    public R update(@RequestBody BaoxiaozhiduEntity baoxiaozhidu, HttpServletRequest request){
        //ValidatorUtils.validateEntity(baoxiaozhidu);
        baoxiaozhiduService.updateById(baoxiaozhidu);//全部更新
        return R.ok();
    }



    

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @SysLog("删除报销制度")
    public R delete(@RequestBody Long[] ids){
        baoxiaozhiduService.deleteBatchIds(Arrays.asList(ids));
        return R.ok();
    }

    	









}
